package com.ev.k3cloudBusiness.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ev.framework.annotation.EvApiByToken;
import com.ev.framework.utils.R;
import com.ev.k3cloudBusiness.service.K3StkStockCountGainService;
import com.ev.k3cloudBusiness.vo.K3StkStockCountGainInsertVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "/", tags = "金蝶K3Cloud盘盈单")
@RestController
public class K3StkStockCountGainController {
    @Autowired
    K3StkStockCountGainService k3StkStockCountGainService;
    @EvApiByToken(value = "/apis/stockCountGain/insert", method = RequestMethod.POST, apiTitle = "新增盘盈单")
    @ApiOperation("新增盘盈单")
    public R insert(@RequestBody @ApiParam("param") K3StkStockCountGainInsertVo param) {
        try {
            String result = k3StkStockCountGainService.insert(param);
            JSONObject resultObj = JSON.parseObject(result);
            if( resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getBooleanValue("IsSuccess") ) {
                return R.ok();
            } else {
                return R.error(resultObj.getJSONObject("Result").getJSONObject("ResponseStatus").getJSONArray("Errors").toString());
            }
        }
        catch (Exception ex) {
            return R.error(ex.getMessage());
        }
    }
}
